package com.example.lijinyuan.mybutton;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.Button;

/**
 * Created by lijinyuan on 16/3/23.
 */
public abstract class EntityButton {

    private String code;
    private Context context;
    private Button button1;
    private Button button2;
    private Button button3;
    private String type;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Button getButton1() {
        return button1;

    }

    public void setButton1(Button button1) {
        this.button1 = button1;
    }

    public Button getButton2() {
        return button2;
    }

    public void setButton2(Button button2) {
        this.button2 = button2;
    }

    public Button getButton3() {
        return button3;
    }

    public void setButton3(Button button3) {
        this.button3 = button3;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    private EntityButton getE() {
        return this;
    }


    private View.OnClickListener onClickListener1;
    private View.OnClickListener onClickListener2;

    private View.OnClickListener onClickListener3;

    public View.OnClickListener getOnClickListener1() {
        return onClickListener1;
    }

    public void setOnClickListener1(View.OnClickListener onClickListener1) {
        this.onClickListener1 = onClickListener1;
    }

    public View.OnClickListener getOnClickListener2() {
        return onClickListener2;
    }

    public void setOnClickListener2(View.OnClickListener onClickListener2) {
        this.onClickListener2 = onClickListener2;
    }

    public View.OnClickListener getOnClickListener3() {
        return onClickListener3;
    }

    public void setOnClickListener3(View.OnClickListener onClickListener3) {
        this.onClickListener3 = onClickListener3;
    }

    public EntityButton(Activity context, int ContentResId, int Button1Id, int Button2Id, int Button3Id, String type, String code) {
        this.button1 = (Button) context.findViewById(Button1Id);
        this.button2 = (Button) context.findViewById(Button2Id);
        this.button3 = (Button) context.findViewById(Button3Id);

        setButton(button1, button2, button3, type);

        this.type = type;
        this.code = code;
        this.onClickListener1 = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                button1Click(v, getE());
                Log.d("1111", "aaaaa");

            }
        };

        this.onClickListener2 = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                button2Click(v, getE());
                Log.d("1111", "bbbbbb");

            }
        };

        this.onClickListener3 = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                button3Click(v, getE());
                Log.d("1111", "ccccc");

            }
        };

        this.button1.setOnClickListener(onClickListener1);
        this.button2.setOnClickListener(onClickListener2);
        this.button3.setOnClickListener(onClickListener3);

    }

    public EntityButton(Activity context, int ContentResId, int Button1Id, int Button2Id, int Button3Id, String type) {
        this.button1 = (Button) context.findViewById(Button1Id);
        this.button2 = (Button) context.findViewById(Button2Id);
        this.button3 = (Button) context.findViewById(Button3Id);


        this.code = type;
        this.onClickListener1 = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                button1Click(v, getE());
                Log.d("1111", "111111");

            }
        };

        this.onClickListener2 = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                button2Click(v, getE());
                Log.d("1111", "22222");

            }
        };

        this.onClickListener3 = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                button3Click(v, getE());
                Log.d("1111", "333333");
            }
        };

        this.button1.setOnClickListener(onClickListener1);
        this.button2.setOnClickListener(onClickListener2);
        this.button3.setOnClickListener(onClickListener3);

    }

    public abstract void button1Click(View v, EntityButton entity);

    public abstract void button2Click(View v, EntityButton entity);

    public abstract void button3Click(View v, EntityButton entity);

    public void setButton(Button button1, Button button2, Button button3, String s) {

        if ("1".equals(s)) {
            button1.setText("去付款");
            button2.setText("取消报名");
            button3.setText("联系学校");

        } else if ("2".equals(s)) {
            button1.setText("申请退款");
            button2.setText("联系学校");
            button3.setVisibility(View.GONE);


        } else if ("3".equals(s)) {
            button1.setText("申请退款");
            button2.setText("联系学校");

            button3.setText("实付款");

        } else if ("4".equals(s)) {
            button1.setText("实付款");
            button2.setText("追加评价");
            button3.setText("联系学校");


        } else if ("5".equals(s)) {
            button1.setText("实付款");
            button2.setText("已学完");
            button3.setText("联系学校");


        }else if ("6".equals(s)) {
            button1.setText("实付款");
            button1.setText("取消退款");
            button1.setText("联系学校");
            button1.setVisibility(View.GONE);

        }else if ("7".equals(s)) {
            button1.setText("实付款");
            button2.setText("再次报名");
            button3.setText("联系学校");



        }else if ("8".equals(s)) {
            button1.setText("实付款");
            button2.setText("再次报名");
            button3.setText("联系学校");


        }else if ("9".equals(s)) {
            button1.setText("实付款");
            button2.setText("再次报名");
            button3.setText("去评价");

        }
//        }else if ("10".equals(s)) {
//            button1.setText("实付款");
//            button1.setText("再次报名");
//            button1.setText("追加评价");
//            button1.setText("联系学校");
//
//        }else if ("11".equals(s)) {
//            button1.setText("实付款");
//            button1.setText("再次报名");
//            button1.setText("联系学校");
//            button1.setVisibility(View.GONE);
//        }else if ("12".equals(s)) {
//            button1.setText("实付款");
//            button1.setText("已学完");
//            button1.setText("联系学校");
//            button1.setVisibility(View.GONE);
//        }

    }
}
